package com.zhy.http.okhttp.utils;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import java.io.InputStream;
import java.lang.reflect.Field;

public class ImageUtils
{
  public static int calculateInSampleSize(ImageSize paramImageSize1, ImageSize paramImageSize2)
  {
    int i = paramImageSize1.width;
    int j = paramImageSize1.height;
    int k = 1;
    int m = paramImageSize2.width;
    int n = paramImageSize2.height;
    if ((i > m) && (j > n))
      k = Math.max(Math.round(i / m), Math.round(j / n));
    return k;
  }

  private static int getExpectHeight(View paramView)
  {
    if (paramView == null)
      return 0;
    ViewGroup.LayoutParams localLayoutParams = paramView.getLayoutParams();
    int i = 0;
    if (localLayoutParams != null)
    {
      int j = localLayoutParams.height;
      i = 0;
      if (j != -2)
        i = paramView.getWidth();
    }
    if ((i <= 0) && (localLayoutParams != null))
      i = localLayoutParams.height;
    if (i <= 0)
      i = getImageViewFieldValue(paramView, "mMaxHeight");
    if (i <= 0)
      i = paramView.getContext().getResources().getDisplayMetrics().heightPixels;
    return i;
  }

  private static int getExpectWidth(View paramView)
  {
    if (paramView == null)
      return 0;
    ViewGroup.LayoutParams localLayoutParams = paramView.getLayoutParams();
    int i = 0;
    if (localLayoutParams != null)
    {
      int j = localLayoutParams.width;
      i = 0;
      if (j != -2)
        i = paramView.getWidth();
    }
    if ((i <= 0) && (localLayoutParams != null))
      i = localLayoutParams.width;
    if (i <= 0)
      i = getImageViewFieldValue(paramView, "mMaxWidth");
    if (i <= 0)
      i = paramView.getContext().getResources().getDisplayMetrics().widthPixels;
    return i;
  }

  public static ImageSize getImageSize(InputStream paramInputStream)
  {
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(paramInputStream, null, localOptions);
    return new ImageSize(localOptions.outWidth, localOptions.outHeight);
  }

  private static int getImageViewFieldValue(Object paramObject, String paramString)
  {
    try
    {
      Field localField = ImageView.class.getDeclaredField(paramString);
      localField.setAccessible(true);
      int i = localField.getInt(paramObject);
      int j = 0;
      if (i > 0)
      {
        j = 0;
        if (i < 2147483647)
          j = i;
      }
      return j;
    }
    catch (Exception localException)
    {
    }
    return 0;
  }

  public static ImageSize getImageViewSize(View paramView)
  {
    ImageSize localImageSize = new ImageSize();
    localImageSize.width = getExpectWidth(paramView);
    localImageSize.height = getExpectHeight(paramView);
    return localImageSize;
  }

  public static class ImageSize
  {
    int height;
    int width;

    public ImageSize()
    {
    }

    public ImageSize(int paramInt1, int paramInt2)
    {
      this.width = paramInt1;
      this.height = paramInt2;
    }

    public String toString()
    {
      return "ImageSize{width=" + this.width + ", height=" + this.height + '}';
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.zhy.http.okhttp.utils.ImageUtils
 * JD-Core Version:    0.6.2
 */